    ORG 0000H
    AJMP main
    ORG 0100H
main://主函数	 
        ; mov 53H,#04H
        ; mov 49H,#01H
        ; mov 58H,#02H
        ; mov 54H,#00H
		; lcall test_1
        ; ljmp init
		mov sp,#60H
        Mov P3,#0FFH ;P1口写入全1 ，设置P1口为输入状态
		mov 40H,#0H	  //40H为第一个数码管内的数字
		mov 41H,#0H	  //以下同理
		mov 42H,#0H
		mov 43H,#0H
		mov 44H,#0H
		mov 45H,#0H
		mov 46H,#0H
		mov 47H,#0H
		mov 30H,#0H	  //40H为第一个数码管内的数字
		mov 31H,#0H	  //以下同理
		mov 32H,#0H
		mov 33H,#0H
		mov r1,#03fH
        mov 59H,#00H
		mov r4,#00H		//矩阵键盘列值
		mov 50H,#0H		//第一个数码管运算数的地址兼结果，四字节
		mov 51H,#0H
		mov 52H,#0H
		mov 53H,#0H
		mov 54H,#0ffH	//定义操作运算符，默认为空，0为+，1为-，2为*，3为/
		mov 55H,#0H		//第二个数码管运算数的地址，四字节
		mov 56H,#0H
		mov 57H,#0H
		mov 58H,#0H
	;;;;数码管显示兼主函数

init://初始化
		mov r0,#40H		//数码管首地址
		mov r2,#0e0H	//最后一个数码管的位选码，先从最后一个亮起
		mov r3,#08H		//八个数码管
		
		
loop:;动态扫描数码管 	
		mov A,r2
		mov p2,a	   //加载位选码
		mov a,r3
		dec a
		mov r0,#40H		//数码管首地址
		addc a,r0
		mov r0,a
		mov a,@r0
		mov dptr,#TAB
		movc a,@a+dptr	 //从地址中取出数字
 		mov p0,a   		//往数码管里送入数字
				//轮询检查按键是否按下
		//lcall DELAY		 //延时待数码管显示稳定				   
		lcall KEY
		mov dptr,#index			   	 			  		 
		mov a,r3						   						 
		dec a
		dec a
		movc a,@a+dptr				 
		mov r2,a		//更新数码管位选码						   
 		djnz r3,loop	//每8个数码管循环一次			    
		ajmp init	
		;;;;数码管显示兼主函数

		;;;检测16键盘
KEY:;检测键盘按键
    LCALL KS ;调用键盘检测子程序KS，如有键按下A中内容非0
    JNZ K1  ;A中内容非0，则可能键按下，跳K1
    lcall d1ms ;调用10ms延时去抖,
    lcall check_left
	jnz  next_judge
	ret
    next_judge:
        mov 60H,#00H
        mov a,R7
        push acc
        mov r7,54H  //54H里为运算符
        cjne r7,#04H,second_1
        pop acc
        mov r7,a
        lcall hex_bin
        mov a,30H
        mov 55H,A
        mov a,31H
        mov 56H,A
        mov a,32H
        mov 57H,A
        mov a,33H
        mov 58H,a
        mov 49H,59H
        mov 59H,#00H
        lcall cal_ans
        lcall bin_dec
        ret
    second_1:
        cjne r7,#0ffH,second_num
        pop acc
        mov r7,a
        ret
second_num:;计算保存第一个操作数
	pop acc
	mov r7,a
	lcall hex_bin
	mov a,30H
	mov 50H,A
	mov a,31H
	mov 51H,A
	mov a,32H
	mov 52H,A
	mov a,33H
	mov 53H,a
    mov a,59H
    mov 59H,#00H
    cjne a,#01H,next_clear_all
    mov 49H,#01H
    next_clear_all:
	lcall clear_all
	ret


K1: 
	LCALL D1ms ;可能有键按下，调用延时10ms子程序（见例5-8）去抖动,
    LCALL KS ;再调用键盘检测子程序
	jnz 	k2
	ret

    back:
        ret
K2: 
		mov p1,#0fH	//00001111
		jb p1.3,give_1
		mov r4,#00H
	give_1:
		jb p1.2,give_2
		mov r4,#01H
	give_2:
		jb p1.1,give_3
		mov r4,#02H
	give_3:
		jb p1.0,give_4
		mov r4,#03H
	give_4:
	give_end:
	K3: 
		MoV P1,#00fH ;将R2的列扫描值值送P1口，驱动P1.4为低
		mov p1,#0f0H
L0:
    JB P1.7,L1 ;判行线电平，P1.0等于1，则0行无键按下跳L1，检测1行 //傻逼教材和电路图，不管是行线还是列线都是低电平判断
    MoV A,#00H ;将0行的首键号送入ACC
    lcall LK ;跳转到键号计算程序
	lcall print_num
	ret

L1:
    JB P1.6,L2 ;P1.1等于1跳转到L2，检测2行
    MoV A,#04H ;将1行的首键号送入ACC
    lcall LK ;跳转到键号计算程序
    lcall print_num
    ret
L2: 
    JB P1.5,L3 ;判行线电平，P1.0等于1，则0行无键按下跳L1，检测1行
    MoV A,#08H ;将0行的首键号送入ACC
    lcall LK ;跳转到键号计算程序
	lcall print_num
    ret
L3:
    //JB P1.4,NEXT ;P1.3等于1跳转到NEXT处，为扫描下一列做准备
    MOV A,#0cH ;将3行的首键号送入ACC
	lcall LK
    lcall judge
	ret
LK:
    ADD A,R4 ;行值与列值相加后的?
	push acc
	cjne r4,#03H,clear_r4
	mov r4,#00H
    clear_r4:
botton_x:;//待松开
	lcall d1ms
	lcall ks
	jnz botton_x
	pop acc
	ret
	;;延时10ms顺便显示数码管
D1ms:;//延时10ms顺便显示数码管
        mov r5,#011H
	init_1:
		mov r0,#40H		//数码管首地址
		mov r2,#0e0H	//最后一个数码管的位选码，先从最后一个亮起
		mov r3,#08H		//八个数码管
        djnz r5,myloop
		sjmp over
	myloop:
        //425个始终周期，要延时就要循环16
		mov a,r3
		dec a
		mov r0,#40H		//数码管首地址
		add a,r0
		mov r0,a
		mov a,@r0
		mov dptr,#TAB
		movc a,@a+dptr	 //从地址中取出数字
 		mov p0,a   		//往数码管里送入数字
 		mov A,r2
		mov p2,a	   //加载位选码
				//轮询检查按键是否按下
		mov a,r5
		push acc
		lcall DELAY		 //延时待数码管显示稳定
		
		pop acc
		mov r5,a				   
		mov dptr,#index			   	 			  		 
		mov a,r3						   						 
		dec a
		dec a
		movc a,@a+dptr				 
		mov r2,a		//更新数码管位选码						   
 		djnz r3,myloop	//每8个数码管循环一次			    
		ajmp init_1
	over:        
        RET ;子程序返回
		;;延时10ms顺便显示数码管

K4: 
	LCALL KS ;调用按键检测程序
    JNZ K4 ;按键没有松开继续返回检测
    POP ACC ;按键松开，将堆栈中的键号送入ACC
    RET
KS: 
	MoV P1,#00fH ;按键检测程序，将P1口高4位置0，低4位置1，为输入
    MOV A,P1 ;读入P1口低4位，即读行线的状态
    XRL A,#00fH ;将两次行线的状态相异或，结果送入A，如无键按下，则A=0
    RET

	;;检测16键盘

	;;检测4键盘

next:
	ret

	;;检测4键盘

D10ms:;5000个djnz,10000个时钟周期
            MOV R7,#25
            ;延时10ms子程序，采用双重循环
            D1:
            MOV R6,#200
            DJNZ R6,$
            ;R6减1非0，原地跳转
            DJNZ R7,D1
            RET ;子程序返回
print_num:;打印数字到数码管
	push acc
	mov a,41H
	mov 40H,a
	mov a,42H
	mov 41H,a
	mov a,43H
	mov 42H,a
	mov a,44H
	mov 43H,a
	mov a,45H
	mov 44H,a
	mov a,46H
	mov 45H,a
	mov a,47H
	mov 46H,a
	pop acc
    inc a
    cjne a,#0aH,not_zero
    mov a,#00H
    not_zero:
	mov 47H,a
	ret
    ;撤回子函数
print_num_back:;撤回
	mov a,46H
    mov 47H,a
	mov a,45H
	mov 46H,a
	mov a,44H
	mov 45H,a
	mov a,43H
	mov 44H,a
	mov a,42H
	mov 43H,a
	mov a,41H
	mov 42H,a
	mov a,40H
	mov 41H,a
    mov 40H,#0H
	ret
	;;;//将各数码管的数值转换为二进制

judge:;判断运算符
    cjne a,#0eH,judge_1
    lcall print_num_back
    ret
	judge_1:
		cjne a,#0fH,judge_2
        test_1:
		lcall hex_bin	
		mov a,30H
		mov 55H,A
		mov a,31H
		mov 56H,A
		mov a,32H
		mov 57H,A
		mov a,33H
		mov 58H,a
        mov 60H,59H
        mov 59H,#00H
        mov a,49H
        cjne a,#00H,first_not_is_zhengshu
        mov a,60H
        cjne a,#00H,second_not_is_zhengshu
        lcall cal_ans   ;两个正数运算
        
        ljmp judge_overflow_test
        ret
        second_not_is_zhengshu:
        mov a,54H       ;一个正数与负数
        cjne a,#00H,not_is_add
        mov 54H,#01H    ;正数与负数做加法相当于两个正数相减
        mov 60H,#00H    
        lcall cal_ans
        ljmp judge_overflow_test
        ret
        not_is_add:
        cjne a,#01H,not_is_sub
        mov 54H,#00H    ;正数与负数做减法相当于两个正数相加
        mov 60H,#00H
        call cal_ans
        ljmp judge_overflow_test
        ret
        not_is_sub: 
        mov 49H,#01H    ;正数与负数做乘除等价于负数与正数做乘除
        mov 60H,#00H
        lcall cal_ans
        ljmp judge_overflow_test
        ret

        judge_2:
		cjne  a,#0dH,judge_last
		lcall clear_all
        mov 49H,#00H
		ret

        ;第一个数为负数
        first_not_is_zhengshu:
        mov a,60H       ;负数与
        cjne a,#00H,second_not_is_zhengshu_1
        mov a,54H       ;负数与正数
        cjne a,#00H,not_is_add_1
        mov 60H,#00h    ;负数与正数做加法
        lcall myswap
        mov 54H,#01H    ;惊天BUG，又忘写了，服了
        lcall cal_ans
        ljmp judge_overflow_test
        ret
        not_is_add_1:
        cjne a,#01H,not_is_sub_1
        mov  54H,#00H     ;负数与正数做减法
        lcall cal_ans
        ljmp judge_overflow_test
        ret
        not_is_sub_1:
        lcall cal_ans
        ljmp judge_overflow_test
        ret
        second_not_is_zhengshu_1:
        mov a,54H
        cjne a,#00H,not_is_add_2
        mov 54H,#00H    ;负数与负数做加法
        lcall cal_ans
        ljmp judge_overflow_test
        ret
        not_is_add_2:
        cjne a,#01H,not_is_sub_2
        lcall myswap    ;负数与负数做减法
        lcall cal_ans
        ljmp judge_overflow_test
        ret
        not_is_sub_2:
        mov 49H,#00H
        lcall cal_ans
        ljmp judge_overflow_test
        ret
        judge_overflow_test:
        lcall judge_overflow
        mov a,47H
        cjne a,#0eH,next_step
        ret
        next_step:
		lcall bin_dec
		ret
	
	judge_last:
		lcall print_num
		ret
	;     	cjne a,#0eH,nor_2     ;需要思考的逻辑
	;     lcall print_num_back
	;     ret
	; nor_2:lcall print_num
	; 	ret

myswap:;交换操作数
    mov a,50H
    xch a,55H
    mov 50H,a
    mov a,51H
    xch a,56H
    mov 51H,a
    mov a,52H
    xch a,57H
    mov 52H,a
    mov a,53H
    xch a,58H
    mov 53H,a
    ret
cal_ans:;计算二元运算得出结果
	push acc
	mov a,54H
    cjne a,#0ffH,next_add
    pop acc
    ret
    next_add:
	cjne a,#00H,next_sub
	pop acc
	lcall add_fun
    mov 54H,#0ffH
	ret
	next_sub:
	cjne a,#01H,next_mul
	pop acc
	lcall sub_fun
    mov 54H,#0ffH
	ret
	next_mul:
	cjne a,#02H,next_div
	pop acc
	lcall mul_fun
    mov 54H,#0ffH
	ret
	next_div:
	pop acc
	lcall div_fun
    mov 54H,#0ffH
    ret
clear_all:;清屏
    mov 40H,#0H
    mov 41H,#0H
    mov 42H,#0H
    mov 43H,#0H
    mov 44H,#0H
    mov 45H,#0H
    mov 46H,#0H
    mov 47H,#0H
    ; mov 49H,#00H
    ret
check_left:;检测左边按键
	MOV P3,#0FFH      ;把p3口全部置1
	MOV A,P3          
	CPL A             ;取反，若有按键按下，则不全为0
	JZ  BACK_c          ;若全为0，则无按键按下，跳转到back回到主程序
	LCALL D1ms         ;延时消除抖动
	MOV A,P3
	CPL A
	JZ  BACK_c          ;同上，检测按钮
	JB ACC.0,JIAN     ;若为1，则减按钮按下
	JB ACC.1,JIA      ;若为1，则加按钮按下
	JB ACC.2,CHENG    ;
	JB ACC.3,CHU
	MOV 54H,#0FFH
	BACK_c: 
	ret        ;返回主函数
	JIA:
	MOV 54H,#00H
	ret
	JIAN:
	MOV 54H,#01H
	ret
	CHENG:
	MOV 54H,#02H
	ret
	CHU:
	MOV 54H,#03H
	ret
DELAY:;延时子程序，不显示

	MOV R5,#10 ;延时子程序
	DEL0: 
		MOv R6,#1
	DEL1:
		MOV R7,#20
	DEL2: 
		DJNZ R7,DEL2
		DJNZ R6,DEL1
		DJNZ R5,DEL0
	RET 

add_fun:;加法小模块
	clr A
	clr c
	mov a,53H
	addc a,58H
	mov 53H,a
	mov a,52H
	addc a,57H
	mov 52H,a
	mov a,51H
	addc a,56H
	mov 51H,a
	mov a,50H
	addc a,55H
	mov 50H,a
	ret
sub_fun:;减法小模块
    BUG_test_1:
	clr c
	mov a,53H
	subb a,58H
	mov 33H,a
	mov a,52H
	subb a,57H
	mov 32H,a
	mov a,51H
	subb a,56H
	mov 31H,a
	mov a,50H
	subb a,55H
	mov 30H,a

	jc not_sub
	mov 53H,33H
	mov 52H,32H
	mov 51H,31H
	mov 50H,30H
    mov 49H,#00H
	ret
	not_sub:
	clr c
	mov a,58H
	subb a,53H
	mov 53H,A
	mov a,57H
	subb a,52H
	mov 52H,a
	mov a,56H
	subb a,51H
	mov 51H,a
	mov a,55H
	subb a,50H
	mov 50H,a
	mov 49H,#01H
	ret

mul_fun:;乘法小模块
    CLR C
    CLR F0
    MOV A,58H
    MOV B,53H
    MUL AB
    MOV 74H,A
    MOV 73H,B

    MOV A,58H
    MOV B,52H
    MUL AB
    MOV C,F0
    ADDC A,73H
    MOV F0,C
    MOV 73H,A
    MOV A,B
    MOV 72H,A

    MOV A,58H
    MOV B,51H
    MUL AB
    MOV C,F0
    ADDC A,72H
    MOV F0,C
    MOV 72H,A
    MOV A,B
    MOV 71H,A

    MOV A,58H
    MOV B,50H
    MUL AB
    MOV C,F0
    ADDC A,71H
    MOV F0,C
    MOV 71H,A
    MOV A,B
    MOV 70H,A
    MOV A,70H
    ADDC A,#00H
    MOV 70H,A

    //
    CLR C
    CLR F0
    MOV A,57H
    MOV B,53H
    MUL AB
    MOV C,F0
    ADDC A,73H
    MOV F0,C
    MOV 73H,A
    MOV C,F0
    MOV A,B
    ADDC A,72H
    MOV F0,C
    MOV 72H,A

    MOV A,57H
    MOV B,52H
    MUL AB
    MOV C,F0
    ADDC A,72H
    MOV F0,C
    MOV 72H,A
    MOV C,F0
    MOV A,B
    ADDC A,71H
    MOV F0,C
    MOV 71H,A

    MOV A,57H
    MOV B,51H
    MUL AB
    MOV C,F0
    ADDC A,71H
    MOV F0,C
    MOV 71H,A
    MOV C,F0
    MOV A,B
    ADDC A,70H
    MOV F0,C
    MOV 70H,A
    MOV A,70H
    ADDC A,#00H
    MOV 70H,A
    //
    CLR C
    CLR F0
    MOV A,56H
    MOV B,53H
    MUL AB
    MOV C,F0
    ADDC A,72H
    MOV F0,C
    MOV 72H,A
    MOV C,F0
    MOV A,B
    ADDC A,71H
    MOV F0,C
    MOV 71H,A

    MOV A,57H
    MOV B,51H
    MUL AB
    MOV C,F0
    ADDC A,71H
    MOV F0,C
    MOV 71H,A
    MOV C,F0
    MOV A,B
    ADDC A,70H
    MOV F0,C
    MOV 70H,A
    MOV A,70H
    ADDC A,#00H
    MOV 70H,A
    //
    CLR C
    CLR F0
    MOV A,55H
    MOV B,53H
    MUL AB
    MOV C,F0
    ADDC A,71H
    MOV F0,C
    MOV 71H,A
    MOV C,F0
    MOV A,B
    ADDC A,70H
    MOV F0,C
    MOV 70H,A
    MOV A,70H
    ADDC A,#00H
    MOV 70H,A
    //
    MOV 53H,74H
    MOV 52H,73H
    MOV 51H,72H
    MOV 50H,71H
        ret
div_fun:;除法小模块
    lcall div_start_1
    ret
    ;子函数说明，30到33H为被除数，34H到38H为除数
    circle_div_1:		
				//子程序功能实现4字节r0,r1,r2,r3左移一位
                mov a,r7
				rlc a
				xch a,r7
                mov a,r6
				rlc a
				xch a,r6
                mov a,r5
				rlc a
				xch a,r5
				mov a,r4
				rlc a
				xch a,r4
				mov a,r3
				rlc a
				xch a,r3
				mov a,r2
				rlc a
				xch a,r2
				mov a,r1
				rlc a
				xch a,r1
				mov a,r0
				rlc a
				xch a,r0
				ret
	div_start_1:
				//30h,31h,32h,33h保存被除数，默认为4字节r0,r1为零
				mov r4,50H
				mov r5,51H
				mov r6,52H
				mov r7,53H
				; mov r5,37H被除数
				mov r0,#0H
				mov r1,#0H
				mov r2,#0H
				mov r3,#0H
				; mov a,r1
				mov b,#21H //被除数左移次数，默认为4字节除1字节
				;;//
	div_loop_1:   
				mov a,r3
                subb a,58H
                mov a,r2
                subb a,57H
                mov a,r1
                subb a,56H
                mov a,r0
                subb a,55H
				jc esub_1
                mov a,r3
                subb a,58H
                mov r3,a
				mov 38H,a
                mov a,r2
                subb a,57H
                mov r2,a
				mov 37H,a
                mov a,r1
                subb a,56H
                mov r1,a
				mov 36H,a
                mov a,r0
                subb a,55H
				mov r0,a
				mov 35H,a
				setb c
				lcall circle_div_1
				djnz b,div_loop_1
				ajmp div_end_1
	esub_1:		
				clr c
				mov 38H,58H
				mov 37H,57H
				mov 36H,56H
				mov 35H,55H
				lcall circle_div_1
				djnz b,div_loop_1
	div_end_1:    
                mov 50H,r4
                mov 51H,r5
                mov 52H,r6
                mov 53H,r7
                mov 34H,55H
                mov 35H,56H
                mov 36H,57H
                mov 37H,58H
				ret
bin_dec:;内存里的二进制转数码管的十进制
	; mov 50H,#01H//测试数据
	; mov 51H,#35H
	; mov 52H,#5dH
	; mov 53H,#3cH
	;;//子程序参数说明，将50H到53H的数据转化为8个数码管表示的数据
	;入站保护		
	push acc
	; mov a,r0
	; push acc
	; mov a,r1
	; push acc
	; mov a,r2
	; push acc
	; mov a,r3
	; push acc
	; mov a,r4
	; push acc
	; mov a,r5
	; push acc
	; mov a,r6
	; push acc
	; mov a,r7
	; push acc
	mov r1,50H
	mov r2,51H
	mov r3,52H
	mov r4,53H
	lcall div_start_pre
	mov 47H,a
	lcall div_start_pre
	mov 46H,a
	lcall div_start_pre
	mov 45H,a
	lcall div_start_pre
	mov 44H,a
	lcall div_start_pre
	mov 43H,a
	lcall div_start_pre
	mov 42H,a
	lcall div_start_pre
	mov 41H,a
	lcall div_start_pre
	mov 40H,a
    lcall judge_negative
	; pop acc
	; mov r7,A
	; pop acc
	; mov r6,A
	; pop acc
	; mov r5,A
	; pop acc
	; mov r4,A
	; pop acc
	; mov r3,A
	; pop acc
	; mov r2,A
	; pop acc
	; mov r1,A
	; pop acc
	; mov r0,A
	pop acc
	ret
	circle_div:		
				//子程序功能实现4字节r0,r1,r2,r3左移一位
				mov a,r4
				rlc a
				xch a,r4
				mov a,r3
				rlc a
				xch a,r3
				mov a,r2
				rlc a
				xch a,r2
				mov a,r1
				rlc a
				xch a,r1
				mov a,r0
				rlc a
				xch a,r0
				ret
	div_start_pre:
		mov a,r1
		mov 30H,a
		mov a,r2
		mov 31H,a
		mov a,r3
		mov 32H,a
		mov a,r4
		mov 33H,a
		mov 36H,#00H
		mov 37H,#0aH
	div_start:
				//30h,31h,32h,33h保存被除数，默认为4字节r0,r1为零
				mov r1,30H
				mov r2,31H
				mov r3,32H
				mov r4,33H
				mov r5,37H
				mov r0,#0H
				mov a,r1
				mov r7,#21H //被除数左移次数，默认为4字节除1字节
				;;//
	div_loop:   
				
				mov a,r0
				subb a,r5
				jc esub
				mov r0,a
				setb c
				lcall circle_div
				djnz r7,div_loop
				ajmp div_end
	esub:		
				clr c
				lcall circle_div
				djnz r7,div_loop
	div_end:
				ret
    judge_negative:
            ; mov a,40H//负数溢出判断待实现
            ; jz judge_negative_1
            ; ret
        judge_negative_1:
            mov a,41H
            jz judge_negative_2
            mov a,49H
            jz ret_back
            mov 40H,#0cH
            ret
        judge_negative_2:
            mov a,42H
            jz judge_negative_3
            mov a,49H
            jz ret_back
            mov 41H,#0cH
            ret
        judge_negative_3:
            mov a,43H
            jz judge_negative_4
            mov a,49H
            jz ret_back
            mov 42H,#0cH
            ret
        judge_negative_4:
            mov a,44H
            jz judge_negative_5
            mov a,49H
            jz ret_back
            mov 43H,#0cH
            ret
        judge_negative_5:
            mov a,45H
            jz judge_negative_6
            mov a,49H
            jz ret_back
            mov 44H,#0cH
            ret
        judge_negative_6:
            mov a,46H
            jz judge_negative_7
            mov a,49H
            jz ret_back
            mov 45H,#0cH
            ret
        judge_negative_7:
            mov a,47H
            jz judge_negative_8
            mov a,49H
            jz ret_back
            mov 46H,#0cH
            ret
        judge_negative_8:
        ret_back:
        ret
hex_bin:;数码管理的十进制转二进制到内存中
            ;40H到47H为各数码管内的数字,48H为临时地址值为10,30H到33H为结果，规定为临时地址
			; mov  40H,#9H
            ; mov  41H,#8H
            ; mov  42H,#7H
            ; mov  43H,#6H
            ; mov  44H,#5H
            ; mov  45H,#4H
            ; mov  46H,#3H
            ; mov  47H,#2H
            mov  48H,#0aH
            mov 30H,#00H
            mov 31H,#00H
            mov 32H,#00H
            mov 33H,#0H
            //计算98765432
            lcall ac_mul //0*10+9
            clr c
			mov r4,40H
            cjne r4,#0cH,noeof_1
            mov 59H,#01H
            ; mov 49H,#01H//又是逆天BUG
            mov r4,#00H
            noeof_1:
            lcall add_ans
			mov 48H,#0aH
            lcall ac_mul//9*10+8
			clr c
			mov r4,41H
            cjne r4,#0cH,noeof_2
            mov 59H,#01H

            ; mov 49H,#01H//又是逆天BUG
            mov r4,#00H
            noeof_2:
            lcall add_ans
			mov 48H,#0aH
			lcall ac_mul//987
			clr c
			mov r4,42H
            cjne r4,#0cH,noeof_3
            ; mov 49H,#01H//又是逆天BUG
            mov 59H,#01H

            mov r4,#00H
            noeof_3:
            lcall add_ans
			mov 48H,#0aH
			lcall ac_mul//9876
			clr c
			mov r4,43H
            cjne r4,#0cH,noeof_4
            ; mov 49H,#01H
            mov 59H,#01H

            mov r4,#00H
            noeof_4:
            lcall add_ans
			mov 48H,#0aH
            lcall ac_mul//98765
            clr c
			mov r4,44H
            cjne r4,#0cH,noeof_5
            ; mov 49H,#01H
            mov 59H,#01H

            mov r4,#00H
            noeof_5:
            lcall add_ans
			mov 48H,#0aH
			lcall ac_mul//987654
            clr c
			mov r4,45H
            cjne r4,#0cH,noeof_6
            ; mov 49H,#01H
            mov 59H,#01H

            mov r4,#00H
            noeof_6:
            lcall add_ans
			mov 48H,#0aH
			lcall ac_mul//9876543
            clr c
			mov r4,46H
            cjne r4,#0cH,noeof_7
            ; mov 49H,#01H
            mov 59H,#01H

            mov r4,#00H
            noeof_7:
            lcall add_ans
			mov 48H,#0aH
			lcall ac_mul//98765432
            clr c
			mov r4,47H
            cjne r4,#0cH,noeof_8
            ; mov 49H,#01H
            mov 59H,#01H

            mov r4,#00H
            noeof_8:
            lcall add_ans
			mov 48H,#0aH
			RET
	circle:		
			//子程序功能实现4字节r0,r1,r2,r3左移一位
			mov a,r3
			rlc a
			xch a,r3
			mov a,r2
			rlc a
			xch a,r2
			mov a,r1
			rlc a
			xch a,r1
			mov a,r0
			rlc a
			xch a,r0
			ret
	ac_mul:     //入栈保护
	SETB RS0
	SETB RS1
            ;mov a,r0
            ;push acc
            mov r0,#0H
            ;mov a,r1
            ;push acc
            mov r1,#0H
            ;mov a,r2
            ;push acc
            mov r2,#0H
            ;mov a,r3
            ;push acc
            mov r3,#0H
            ;mov a,r7
            ;push acc
            mov r7,#8H
	mul_start:  
			mov r6,48H	//第二个乘数
			mov a,r6
			clr c
			rlc a
			xch a,48H  //左移第二格操作数
            clr A
            addc a,#00H
            push acc
			lcall circle
            pop acc
            jz hex_bin_next    //判断cy然后将及结果相加
			lcall add_1
	hex_bin_next:		
            djnz r7,mul_start
            //出栈恢复
            ;pop acc
            ;mov r7,A
            ;pop acc
            mov 33H,r3
            ;mov r3,A
            ;pop acc
            mov 32H,r2
            ;mov r2,a
            ;pop acc
            mov 31H,r1
            ;mov r1,a
            ;pop acc
            mov 30H,r0
            mov r0,a
			CLR RS0
			CLR RS1
			ret
	add_1:
		clr c   //将cy清零
        mov a,r3
        addc a,33H
        mov r3,A
        mov a,r2
        addc a,32H
        mov r2,a
        mov a,r1
        addc a,31H
        mov r1,a
        mov a,r0
        addc a,30H
        mov r0,a
        clr A
        ret
	add_ans:
        clr c
		mov a,33H
		addc a,r4
		mov 33H,a
		mov a,32H
		addc a,#0H
		mov 32H,a
		mov a,31H
		addc a,#0H
		mov 31H,a
		mov a,30H
		addc a,#0H
		mov 30H,a
		ret			 
	;;;//将各数码管的数值转换为二进制
	;;;//将各数码管的数值转换为二进制
judge_overflow:;溢出判断
    JCYC:
    MOV A,49H
    CJNE A,#01H,ZSPD
    MOV A,50H
    CJNE A,#00H,ZYCR
    LJMP FYC1
    FYC1:
    MOV A,51H
    CLR C
    SUBB A,#98H
    MOV F0,C
    CJNE A,#00H,ZYCER
    LJMP FYC2
    FYC2:
    MOV A,52H
    CLR C
    SUBB A,#96H
    MOV F0,C
    CJNE A,#00H,ZYCER
    LJMP FYC3

    FYC3:
    MOV A,53H
    CLR C
    SUBB A,#7FH
    MOV F0,C
    CJNE A,#00H,ZYCER
    RET
    ZSPD:
    MOV A,50H
    CLR C
    SUBB A,#05H
    MOV F0,C
    CJNE A,#00H,ZYCER
    LJMP ZYC1

    ZYC1:
    MOV A,51H
    CLR C
    SUBB A,#0F5H
    MOV F0,C
    CJNE A,#00H,ZYCER
    LJMP ZYC2

    ZYC2:
    MOV A,52H
    CLR C
    SUBB A,#0E0H
    MOV F0,C
    CJNE A,#00H,ZYCER
    LJMP ZYC3

    ZYC3:
    MOV A,53H
    CLR C
    SUBB A,#0FFH
    MOV F0,C
    CJNE A,#00H,ZYCER
    RET
    //PDBACK:
    //RET
    ZYCER:
    JNB F0,ZYCR
    RET
    ZYCR:
    mov 40H,#0H	  //40H为第一个数码管内的数字
    mov 41H,#0H	  //以下同理
    mov 42H,#0H
    mov 43H,#0H
    mov 44H,#0H
    mov 45H,#0H
    mov 46H,#0H
    mov 47H,#0eH
    ret
index:
DB 0ffH,0faH,0f7H,0f3H,0ecH,0ebH,0e7H,0e0H;	  //位选码
TAB: 
DB 03fH,006h,05bh,04fh,066h,06dh,07dh,007h,07fh,06fh
DB 03fH,07cH,040H,05eH,079H,071H,073H,03eH,06eH,076H,038H,040H,000H;
;数字字符0~9,a-f,p,u,y,h,l,-,熄灭的共阴极段码表
END